#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>


// ledtest /dev/myled on
// ledtest /dev/myled off

int main(int argc, char* argv[])
{
	int fd;
	char status = 0;
	
	if(argc != 3)
	{
		printf("Usage:ledtest /dev/myled on\nledtest /dev/myled off\n");
		return 0;
	}

	if(strcmp(argv[1],"/dev/myled") == 0)
	{
		//open
		fd = open(argv[1], O_RDWR);
		if(fd < 0)
		{
			printf("open /dev/myled err\n");
			return -1;
		}
		
		//write
		if(strcmp(argv[2],"on") == 0)
		{
			status = 1;
			write(fd, &status, 1);
		}
		else if(strcmp(argv[2], "off") == 0)
		{
			status = 0;
			write(fd, &status, 1);
		}
	}

	return 0;
}
